package android.activities;

import android.app.Activity;
import android.content.Intent;
import android.database.Database;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;

public class NewBaseActivity extends Activity implements OnClickListener {
	
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.new_base);
        View button4 = findViewById(R.id.button4);
        button4.setOnClickListener(this);
        View button5 = findViewById(R.id.button5);
        button5.setOnClickListener(this);
    }
    
    public void onClick(View v) {
    	switch(v.getId()) {
    	case R.id.button4:
    		Intent i = new Intent(this, MenuActivity.class);
    		finish();
    		startActivity(i);
    		break;
    	case R.id.button5:
    		Database database = new Database(this); 		
    		EditText editText1 = (EditText) findViewById(R.id.editText1);
    		EditText editText14 = (EditText) findViewById(R.id.editText14);
    		EditText editText15 = (EditText) findViewById(R.id.editText15);
    		boolean add = false;
    		if(editText14.getText().toString().equals(editText15.getText().toString())) {
    			add = database.addBase(editText1.getText().toString(), editText14.getText().toString());
    		}
    		else {
    			i = new Intent(this, WrongPasswordsActivity.class);
    			startActivity(i);
    		}
    		if(add == true) {
	    		i = new Intent(this, BasesActivity.class);
	    	    startActivity(i);
    		}
    		else
    		{
    			Intent in = new Intent(this, BaseExistActivity.class);
    			startActivity(in);
    		}
    		break; 
    	}
    }
}
